package jjn.daily;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * @author Jjn
 * @since 2023/8/16 23:06
 */
public class LeetCode2682 {
    public int[] circularGameLosers(int n, int k) {
        boolean[] visited = new boolean[n];
        int index = 0;
        visited[index] = true;
        int count = 1;
        while (true) {
            index = (index + k * count) % n;
            if (visited[index]) {
                break;
            }
            count++;
            visited[index] = true;
        }
        List<Integer> result = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (visited[i]) {
                continue;
            }
            result.add(i);
        }
        int[] res = new int[result.size()];
        for (int i = 0; i < result.size(); i++) {
            res[i] = result.get(i) + 1;
        }
        return res;
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] gameLosers = new LeetCode2682().circularGameLosers(n, k);
        System.out.println(Arrays.toString(gameLosers));
    }
}
